using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BookSpace;
using IntegrationGroup;

public partial class BookProfile : System.Web.UI.Page
{
    IntegrationGroup.Person currentPerson;
    BookSpace.Book currentBook;
    IntegrationGroup.Book currentBook2;

    protected void Page_Load(object sender, EventArgs e)
    {
        BookInfoPanel.Visible = true;
        AuthUserPanel.Visible = true;
        RemoteAdminPanel.Visible = true;

        try
        {
            currentPerson = IntegrationGroup.Person.GetPerson(User.Identity.Name);
        }
        catch (Exception error) { }


        //AuthUser, RemoteAdmin
        if (User.IsInRole("AuthUser") == true)
        {
            //unhide panels
            AuthUserPanel.Visible = true;
        }
        if (User.IsInRole("RemoteAdmin") == true)
        {
            //unhide panels
            AuthUserPanel.Visible = true;
            RemoteAdminPanel.Visible = true;
        }

        //create a book
        try
        {
            BookSpace.Book testBook = new BookSpace.Book("Usability Engineering", "Jakob Nielson", "978-0125184069",
                362, "English", "Morgan Kauffman", "Book about usability engineering", "Software/Design",
                "http://ec1.images-amazon.com/images/P/0125184069.01._BO2,204,203,200_PIsitb-dp-500-arrow,TopRight,45,-64_OU01_SCLZZZZZZZ_V45565115_AA240_SH20_.jpg",
                "gadfz");
        }
        catch (Exception x)
        {
        }

        //call the GetBook method to retrieve the book information
        try
        {

            //this uses my Bookspace.Book class
            currentBook = BookSpace.Book.GetBook(Request.QueryString[0]);

            //set all the corresponding text on the page
            BookImage.ImageUrl = currentBook.Url;
            Title.Text = currentBook.Title;
            Author.Text = currentBook.Author;
            ISBN.Text = currentBook.Isbn;
            Pages.Text = currentBook.Pages.ToString();
            Language.Text = currentBook.Language;
            Publisher.Text = currentBook.Publisher;
            //Category.Text = currentBook.Category;
            Description.Text = currentBook.Description;


            /*
            //this uses the Integration.Book class
            Guid _guid = new Guid(Request.QueryString[0]);
            currentBook2 = IntegrationGroup.Book.GetBook(_guid);
            //set all the corresponding text on the page
            BookImage.ImageUrl = currentBook2.ImageUrl;
            Title.Text = currentBook2.Title;
            Author.Text = currentBook2.Author;
            ISBN.Text = currentBook2.ISBN;
            Pages.Text = currentBook2.NumPages.ToString();
            Language.Text = currentBook2.Language;
            Publisher.Text = currentBook2.Publisher;
            Description.Text = currentBook2.Description;
            */

            Page.Header.Title = currentBook.Title + ": " + currentBook.Author;

        }
        catch (IntegrationGroup.NoSuchBook bookError)
        {
            //change this to something useful
            Description.Text = bookError.Message;
        }
        catch (FormatException guid_error)
        {
            //change this to something useful
            Language.Text = guid_error.Message;
        }
        catch (InvalidOperationException connString)
        {
            //change this to something useful
            ISBN.Text = connString.Message;
        }

    }
    protected void AddWantsButton_Click(object sender, EventArgs e)
    {
        //createBookWant?

    }
    protected void AddHavesButton_Click(object sender, EventArgs e)
    {
        //createBookHave?
        //Condition.New, Condition.Excellent, Condition.VeryGood, Condition.Fair, Condition.Poor
        //new, excellent, verygood, fair, poor


        //IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook, 
        if (ConditionDropDown.Text.Equals("New")) { IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook2, Condition.New); }
        else if (ConditionDropDown.Text.Equals("Excellent")) { IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook2, Condition.Excellent); }
        else if (ConditionDropDown.Text.Equals("VeryGood")) { IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook2, Condition.VeryGood); }
        else if (ConditionDropDown.Text.Equals("Fair")) { IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook2, Condition.Fair); }
        else if (ConditionDropDown.Text.Equals("Poor")) { IntegrationGroup.BookHave.CreateBookHave(currentPerson, currentBook2, Condition.Poor); }
        else { ConditionDropDownValidator.Text = "Select a condition..."; }

    }
    protected void RmWantsButton_Click(object sender, EventArgs e)
    {
        //deleteBookWant?
    }
    protected void RmHavesButton_Click(object sender, EventArgs e)
    {
        //deleteBookHave?
    }
    protected void EditBookButton_Click(object sender, EventArgs e)
    {
        //editBook?
    }
}
